from time import sleep
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.select import Select

# 获取Edge浏览器驱动
driver = webdriver.Edge()
# 打开指定网址
driver.get('https://www.jiuxian.com/')
# 强等2秒
sleep(2)
# 窗口最大化
driver.maximize_window()
sleep(2)
# 点击请登录
driver.find_element(By.CLASS_NAME,'headerLogin').click()
sleep(1)
# 输入账号
driver.find_element(By.ID,"userName").send_keys('18185603008')
sleep(2)
# 输入密码
driver.find_element(By.ID,'password').send_keys('123456Aa')
sleep(10)
#点击登录
driver.find_element(By.NAME,'bi_Usuallogin').click()
sleep(2)
# 点击确定
driver.find_element(By.ID,'bindSub').click()
sleep(2)
# 断言
dy1 = driver.find_element(By.XPATH,'/html/body/div[2]/div/div[1]/div/p/span').text
assert dy1 == 'jxw824726828'
print(dy1)
sleep(2)
# 悬浮 我的酒仙
wddd = driver.find_element(By.XPATH, '/html/body/div[2]/div/div[2]/ul/li[1]/div[1]/a')
ActionChains(driver).move_to_element(wddd).perform()
sleep(2)
# 点击我的订单
driver.find_element(By.LINK_TEXT, '我的订单').click()
sleep(2)
# 窗口切换
driver.switch_to.window(driver.window_handles[-1])
sleep(1)
# 向下滑动
driver.execute_script("window.scrollTo(0,800)")
sleep(2)
# 点击收货地址
driver.find_element(By.XPATH, '/html/body/div[5]/div[2]/div[2]/div[4]/a[3]/span').click()
sleep(2)
# 删除先前添加的收货地址
driver.find_element(By.CLASS_NAME, 'controlRemove').click()
sleep(2)
# 断言1
dy1 = driver.find_element(By.CLASS_NAME, 'alertContent').text
print(dy1)
assert '确定要删除吗?' == dy1
sleep(2)
# 点击确定
driver.find_element(By.XPATH, '/html/body/div[8]/div/div[3]/span[1]/b').click()
sleep(2)
# 断言2
dy2 = driver.find_element(By.XPATH, '/html/body/div[8]/div/div[2]/p/span').text
print(dy2)
assert '删除成功！' == dy2
# 点击确定
driver.find_element(By.XPATH, '/html/body/div[8]/div/div[3]/span[1]/b').click()
sleep(2)
# 输入收货人
driver.find_element(By.ID,'people').send_keys('小婷')
sleep(2)
# select选择器
# index
province = Select(driver.find_element(By.ID,'province'))
province.select_by_index(1)
sleep(2)
# value
city = Select(driver.find_element(By.ID,'city'))
city.select_by_value('52')
sleep(2)
# visible_text
district = Select(driver.find_element(By.ID,'district'))
district.select_by_visible_text('昌平区')
sleep(2)
# 输入详细地址
driver.find_element(By.ID,'address').send_keys('南口镇南大街21号')
sleep(2)
# 输入邮政编码
driver.find_element(By.ID,'zipcode').send_keys('100001')
sleep(2)
# 输入手机
driver.find_element(By.ID,'iphone').send_keys('18185603008')
sleep(2)
# 输入固定电话
driver.find_element(By.ID,'phone').send_keys('18185603008')
sleep(2)
# 点击提交
driver.find_element(By.ID,'save').click()
sleep(2)
# 断言3
dy3 = driver.find_element(By.XPATH, '/html/body/div[8]/div/div[2]/p/span').text
print(dy3)
assert '保存成功!' == dy3
sleep(2)
# 点击确定
driver.find_element(By.XPATH,'/html/body/div[8]/div/div[3]/span[1]/b').click()
sleep(5)





